<template>
  <div class="app-container">
    <!--案卷信息数据-->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExportArch"
          v-hasPermi="['system:file:exportBook']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-search"
          size="mini"
          @click="handleHeighArch"
          v-hasPermi="['system:file:listBook']"
        >高级查询</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-refresh"
          size="mini"
          @click="resetQuery"
          v-hasPermi="['system:file:listBook']"
        >重置</el-button>
      </el-col>
    </el-row>

    <el-table :data="fileListBook" highlight-current-row border>
      <el-table-column label="总登记号" align="center" prop="archives.registNum" />
      <el-table-column label="分类号" align="center" prop="archives.archiveClassifiNum" />
      <el-table-column label="档号" align="center" prop="archives.archiveFileNum" />
      <el-table-column label="项目代号" align="center" prop="archives.projectCode" />
      <el-table-column
        label="案卷题名"
        align="center"
        prop="archives.caseFileTitle"
        min-width="300px"
        show-overflow-tooltip
      />
      <el-table-column label="微缩号" align="center" prop="archives.miniatureNum" />
      <el-table-column label="档案馆代号" align="center" prop="archives.archiveCode" />
      <el-table-column label="案卷档号" align="center" prop="archives.objStr3" />
      <el-table-column label="录入人" align="center" prop="archives.objStr4" />
      <el-table-column label="责任者" align="center" prop="archives.personLiable" />
      <el-table-column label="编制日期" align="center" prop="archives.compilationDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.archives.compilationDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="存放位置" align="center" prop="archives.storagePosition" />
      <el-table-column label="编制单位" align="center" prop="archives.organization" />
      <el-table-column label="进馆日期" align="center" prop="archives.entryDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.archives.entryDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="总卷数" align="center" prop="archives.totalRolls" />
      <el-table-column label="当前卷" align="center" prop="archives.currentRolls" />
      <el-table-column label="保管期限" align="center" prop="archives.storageTime" />
      <el-table-column label="移交单位" align="center" prop="archives.objStr2" />
      <el-table-column label="密级" align="center" prop="archives.secretLevel" />
      <el-table-column label="文件顺序号" align="center" prop="sequenceNum" />
      <el-table-column label="文件编号" align="center" prop="fileNo" />
      <el-table-column
        label="文件题名"
        align="center"
        prop="docTitle"
        min-width="300px"
        show-overflow-tooltip
      />
      <el-table-column label="档号" align="center" prop="objStr2" />
      <el-table-column label="文图号" align="center" prop="objStr3" />
      <el-table-column label="载体类型" align="center" prop="objStr4" />
      <el-table-column label="责任者" align="center" prop="objStr1" />
      <el-table-column label="页数" align="center" prop="pageCounts" />
      <el-table-column label="页号" align="center" prop="pageNo" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column
        label="文件"
        align="center"
        prop="filePath"
        min-width="300px"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <el-tag type="info" v-if="scope.row.filePath == null">无文件</el-tag>
          <div v-if="scope.row.filePath != null">
            <li
              :key="path"
              class="el-upload-list__item ele-upload-list__item-content"
              v-for="(path, index) in getFilePath(scope.row.filePath)"
            >
              <el-link :href="path" :underline="false" target="_blank">
                <span class="el-icon-document">{{getFileName(path)}}</span>
              </el-link>
            </li>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="图片" align="center" prop="imgPath" width="100">
        <template slot-scope="scope">
          <el-tag type="info" v-if="scope.row.imgPath == null">无图片</el-tag>
          <image-preview
            v-if="scope.row.imgPath != null"
            :src="scope.row.imgPath"
            :width="50"
            :height="50"
          />
          <el-tag
            v-if="scope.row.imgPath != null"
            type="success"
            class="point"
            @click="printImage(scope.row.imgPath)"
          >打印</el-tag>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="totalFile>0"
      :total="totalFile"
      :page.sync="queryParamsFile.pageNum"
      :limit.sync="queryParamsFile.pageSize"
      @pagination="getListFileBook"
      :page-sizes="page_size"
    />

    <!-- 案卷高级查询对话框 -->
    <el-dialog
      :title="heightArch.title"
      :visible.sync="heightArch.open"
      width="560px"
      append-to-body
    >
      <el-row type="flex" justify="space-between">
        <el-col :span="10">
          <el-select v-model="heightParam" filterable clearable placeholder="请选择字段">
            <el-option
              v-for="item in heightOptionArch"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-col>
        <el-col :span="2">
          <div style="padding-left:5px;padding-top:7px">包含</div>
        </el-col>
        <el-col :span="10">
          <el-input v-model="heightValue" placeholder="请输入查询内容" />
        </el-col>
      </el-row>
      <el-row style="margin-top:25px">
        <el-col :span="24">
          <el-form :model="queryParamsArch" ref="queryFormArch" :inline="true" label-width="68px">
            <el-form-item label="归档状态">
              <el-select
                v-model="queryParamsArch.objStr1"
                filterable
                clearable
                placeholder="请选择归档状态"
              >
                <el-option
                  v-for="item in heightOptionFinish"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="编制日期">
              <el-date-picker
                v-model="daterangeCompilationDate"
                size="small"
                style="width: 240px"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                unlink-panels
              ></el-date-picker>
            </el-form-item>
            <el-form-item label="进馆日期">
              <el-date-picker
                v-model="daterangeEntryDate"
                size="small"
                style="width: 240px"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                unlink-panels
              ></el-date-picker>
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="getHeightArch">搜 索</el-button>
        <el-button @click="heightArch.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listFileBook } from "@/api/system/file";
import print from "print-js";

export default {
  data() {
    return {
      // 项目根路径
      baseUrl: process.env.VUE_APP_BASE_API,
      // 分页器每页显示
      page_size: [5, 10, 15, 20, 25, 30, 100],
      // 总条数
      totalFile: 0,
      // 高级查询值
      heightValue: null,
      // 高级查询参数
      heightParam: null,
      // 案卷管理表格数据
      fileListBook: [],
      // 预留字段15时间范围
      daterangeCompilationDate: [],
      // 预留字段15时间范围
      daterangeEntryDate: [],
      // 数据库查询参数
      queryParamsFile: {
        pageNum: 1,
        pageSize: 5,
        sequenceNum: null,
        fileNo: null,
        docTitle: null,
        objStr1: null,
        pageCounts: null,
        pageNo: null,
        archivesId: null,
        filePath: null,
        imgPath: null,
        fileExt: null,
        createTime: null,
        updateTime: null,
        createBy: null,
        updateBy: null
      },
      // 高级查询封装参数
      queryParamsArch: {
        archiveClassifiNum: null,
        archiveFileNum: null,
        archiveCode: null,
        caseFileTitle: null,
        miniatureNum: null,
        projectCode: null,
        personLiable: null,
        compilationDate: null,
        registNum: null,
        storagePosition: null,
        organization: null,
        entryDate: null,
        totalRolls: null,
        currentRolls: null,
        storageTime: null,
        secretLevel: null,
        enginId: null,
        status: null,
        typeId: null,
        createTime: null,
        updateTime: null,
        createBy: null,
        updateBy: null,
        objStr1: null,
        objStr2: null
      },
      // 高级查询参数
      heightArch: {
        // 是否显示弹出层
        open: false,
        // 弹出层标题
        title: ""
      },
      // 高级查询字段参数选项
      heightOptionArch: [
        {
          label: "案卷分类号",
          value: "archiveClassifiNum"
        },
        {
          label: "档号",
          value: "archiveFileNum"
        },
        {
          label: "档案馆代号",
          value: "archiveCode"
        },
        {
          label: "案卷题名",
          value: "caseFileTitle"
        },
        {
          label: "微缩号",
          value: "miniatureNum"
        },
        {
          label: "项目代号",
          value: "projectCode"
        },
        {
          label: "责任者",
          value: "personLiable"
        },
        {
          label: "总登记号",
          value: "registNum"
        },
        {
          label: "存放位置",
          value: "storagePosition"
        },
        {
          label: "编制单位",
          value: "organization"
        },
        {
          label: "总卷数",
          value: "totalRolls"
        },
        {
          label: "当前卷",
          value: "currentRolls"
        },
        {
          label: "密级",
          value: "secretLevel"
        },
        {
          label: "移交单位",
          value: "objStr2"
        }
      ],
      // 归档选项
      heightOptionFinish: [
        {
          label: "未申请",
          value: "0"
        },
        {
          label: "申请中",
          value: "1"
        },
        {
          label: "审核通过",
          value: "2"
        },
        {
          label: "审核拒绝",
          value: "3"
        }
      ]
    };
  },
  created() {
    this.getListFileBook();
  },
  methods: {
    /** 查询案卷管理列表 */
    getListFileBook() {
      this.queryParamsFile.params = {};
      if (
        null != this.daterangeCompilationDate &&
        "" != this.daterangeCompilationDate
      ) {
        this.queryParamsFile.params[
          "beginCompilationDate"
        ] = this.daterangeCompilationDate[0];
        this.queryParamsFile.params[
          "endCompilationDate"
        ] = this.daterangeCompilationDate[1];
      }
      if (null != this.daterangeEntryDate && "" != this.daterangeEntryDate) {
        this.queryParamsFile.params[
          "beginEntryDate"
        ] = this.daterangeEntryDate[0];
        this.queryParamsFile.params[
          "endEntryDate"
        ] = this.daterangeEntryDate[1];
      }
      this.queryParamsFile.params["archiveClassifiNum"] = this.queryParamsArch[
        "archiveClassifiNum"
      ];
      this.queryParamsFile.params["archiveFileNum"] = this.queryParamsArch[
        "archiveFileNum"
      ];
      this.queryParamsFile.params["archiveCode"] = this.queryParamsArch[
        "archiveCode"
      ];
      this.queryParamsFile.params["caseFileTitle"] = this.queryParamsArch[
        "caseFileTitle"
      ];
      this.queryParamsFile.params["miniatureNum"] = this.queryParamsArch[
        "miniatureNum"
      ];
      this.queryParamsFile.params["projectCode"] = this.queryParamsArch[
        "projectCode"
      ];
      this.queryParamsFile.params["personLiable"] = this.queryParamsArch[
        "personLiable"
      ];
      this.queryParamsFile.params["registNum"] = this.queryParamsArch[
        "registNum"
      ];
      this.queryParamsFile.params["storagePosition"] = this.queryParamsArch[
        "storagePosition"
      ];
      this.queryParamsFile.params["organization"] = this.queryParamsArch[
        "organization"
      ];
      this.queryParamsFile.params["totalRolls"] = this.queryParamsArch[
        "totalRolls"
      ];
      this.queryParamsFile.params["currentRolls"] = this.queryParamsArch[
        "currentRolls"
      ];
      this.queryParamsFile.params["secretLevel"] = this.queryParamsArch[
        "secretLevel"
      ];
      this.queryParamsFile.params["objStr2"] = this.queryParamsArch["objStr2"];
      this.queryParamsFile.params["objStr1"] = this.queryParamsArch.objStr1;

      listFileBook(this.queryParamsFile).then(response => {
        this.fileListBook = response.rows;
        this.totalFile = response.total;
      });
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetQueryFile();
      this.resetQueryArch();
      this.getListFileBook();
    },
    /** 重置高级查询封装参数 */
    resetQueryArch() {
      this.daterangeCompilationDate = [];
      this.daterangeEntryDate = [];
      (this.queryParamsArch.archiveClassifiNum = null),
        (this.queryParamsArch.archiveFileNum = null),
        (this.queryParamsArch.archiveCode = null),
        (this.queryParamsArch.caseFileTitle = null),
        (this.queryParamsArch.miniatureNum = null),
        (this.queryParamsArch.projectCode = null),
        (this.queryParamsArch.personLiable = null),
        (this.queryParamsArch.compilationDate = null),
        (this.queryParamsArch.registNum = null),
        (this.queryParamsArch.storagePosition = null),
        (this.queryParamsArch.organization = null),
        (this.queryParamsArch.entryDate = null),
        (this.queryParamsArch.totalRolls = null),
        (this.queryParamsArch.currentRolls = null),
        (this.queryParamsArch.storageTime = null),
        (this.queryParamsArch.secretLevel = null),
        (this.queryParamsArch.enginId = null),
        (this.queryParamsArch.status = null),
        (this.queryParamsArch.createTime = null),
        (this.queryParamsArch.updateTime = null),
        (this.queryParamsArch.createBy = null),
        (this.queryParamsArch.updateBy = null),
        (this.queryParamsArch.objStr1 = null),
        (this.queryParamsArch.objStr2 = null);
    },
    /** 重置文件查询参数 */
    resetQueryFile() {
      this.daterangeCreateTime = [];
      this.daterangeUpdateTime = [];
      this.queryParamsFile.sequenceNum = null;
      this.queryParamsFile.fileNo = null;
      this.queryParamsFile.docTitle = null;
      this.queryParamsFile.objStr1 = null;
      this.queryParamsFile.pageCounts = null;
      this.queryParamsFile.pageNo = null;
      this.queryParamsFile.archivesId = null;
      this.queryParamsFile.filePath = null;
      this.queryParamsFile.imgPath = null;
      this.queryParamsFile.fileExt = null;
      (this.queryParamsFile.createTime = null),
        (this.queryParamsFile.updateTime = null),
        (this.queryParamsFile.createBy = null),
        (this.queryParamsFile.updateBy = null);
    },
    /** 高级查询按钮操作 */
    handleHeighArch() {
      this.heightArch.title = "案卷高级查询";
      this.heightArch.open = true;
      this.resetQueryArch(); // 重置查询参数
      this.resetQueryFile();
    },
    /** 高级查询 */
    getHeightArch() {
      for (let key in this.queryParamsArch) {
        if (key === this.heightParam) {
          this.queryParamsArch[key] = this.heightValue;
          console.log(this.queryParamsArch[key]);
        }
      }
      this.queryParamsFile.pageNum = 1; // 第一页开始查询
      this.getListFileBook();
      this.heightValue = null;
      this.heightParam = null;
      this.heightArch.open = false;
    },
    /** 导出按钮操作 */
    handleExportArch() {
      this.download(
        "system/file/exportBook",
        {
          ...this.queryParamsArch
        },
        `fileBook_${new Date().getTime()}.xlsx`
      );
    },
    // 文件路径处理
    getFilePath(filePaths) {
      var arrayPath = filePaths.split(",");
      for (let i in arrayPath) {
        arrayPath[i] = this.baseUrl + arrayPath[i];
      }
      return arrayPath;
    },
    // 获取文件名称
    getFileName(name) {
      if (name.lastIndexOf("/") > -1) {
        return name.slice(name.lastIndexOf("/") + 1).toLowerCase();
      } else {
        return "";
      }
    },
    // 打印图片
    printImage(imgPaths) {
      var arrayPath = imgPaths.split(",");
      for (let i in arrayPath) {
        arrayPath[i] = this.baseUrl + arrayPath[i];
      }
      print({
        printable: arrayPath,
        type: "image",
        imageStyle: "width:100%;margin-bottom:20px;"
      });
    }
  }
};
</script>

<style>
</style>